home *** CD-ROM | disk | FTP | other *** search
- /*
- * ⌐ Graeme Gerrard 1990
- * Faculty of Music, University of Melbourne
- * Parkville Victoria 3052 Australia.
- *
- * ARPANET: grae@murdu.ucs.unimelb.edu.au
- * telephone: (613) 344 4127, Fax: (613) 344 5346
- */
- #include "Music4C.h"
- #include "Preferences_Dialog.h"
- #include "Music4C_Prototype.h"
- #include "string.h"
-
- void GetMusic4C_Prefs(void);
-
- static pascal char MyFilter (DialogPtr theDialog,
- EventRecord *theEvent, short *itemHit);
-
- static void Refresh_Dialog(DialogPtr GetSelection);
- void SaveMusic4C_Prefs(void);
- void A_ErrorAlert(void);
-
- #define I_OK 1
- #define I_Cancel 2
- #define I_Pass1 3
- #define I_Pass2 4
- #define I_Pass3 5
-
- #define Pass1Test 1
- #define Pass2Test 2
- #define Pass3Test 3
- #define Synthesize 4
-
- static char ExitDialog;
- static Point myPt;
- static char ChangedSelection;
- static MenuHandle tempMenu;
- static long Result;
- static short Popup_I_Run_Up_To;
- static short Popup_I_Sound_File_Format;
- static short Initial_Report_Flags;
-
- /* ********************************************* */
- extern int RunUpTo;
- extern int ReportFlags;
- extern Boolean CreateSoundFile;
- extern int RunToPass1; /* test pass1 only */
- extern int RunToPass2; /* test up to pass2 only */
- extern int RunToPass3; /* test pass3 only, i.e. don't write sample file */
- extern int SFoutputType;
- extern OSErr theErr;
-
- extern int out1_flag; /* pass1 output flag */
- extern int out2_flag; /* pass2 output flag */
- extern int out3_flag; /* pass3 output flag */
-
-
-
-
- void GetMusic4C_Prefs()
- {
- int refNum;
- StringPtr volName;
- char buffer[2];
- long count;
- extern Str255 FileFormat;
- extern Str255 SFDirectoryName;
- extern SysEnvRec SysEnvData;
- int i;
-
- /* "Music4C_Prefs" is kept in the System Folder */
-
- theErr = FSOpen("\pMusic4C_Prefs", SysEnvData.sysVRefNum, &refNum);
- if (theErr) {
- theErr = Create("\pMusic4C_Prefs", SysEnvData.sysVRefNum, 'MU4C', 'TEXT');
- if ( theErr ) { /* call Error Alert */
- ParamText("\pCan't create Preferences file", NIL, NIL, NIL);
- A_ErrorAlert();
- }
- theErr = FSOpen("\pMusic4C_Prefs", SysEnvData.sysVRefNum, &refNum);
- /* we have created & opened the file, write in the default prefs */
- buffer[0] = ReportFlags;
- buffer[1] = RunUpTo;
- count = 2L;
- theErr = FSWrite( refNum, &count, &buffer);
-
- count = sizeof(FileFormat);
- theErr = FSWrite( refNum, &count, &FileFormat); /* default SF format */
-
- count = sizeof(SFDirectoryName);
- theErr = FSWrite( refNum, &count, &SFDirectoryName); /* default SF dir */
-
- if ( theErr != noErr ) {
- ParamText("\pError writing Preferences file", NIL, NIL, NIL);
- A_ErrorAlert();
- }
- volName = NIL;
- theErr = FlushVol (volName, SysEnvData.sysVRefNum);
- theErr = FSClose(refNum);
- theErr = FSOpen("\pMusic4C_Prefs", SysEnvData.sysVRefNum, &refNum);
- }
- /* prefs file is open */
- count = 2L;
- theErr = FSRead (refNum, &count, &buffer);
- if ( theErr != noErr ) {
- ParamText("\pError reading Preferences file", NIL, NIL, NIL);
- A_ErrorAlert();
- }
- ReportFlags = (int)buffer[0];
- RunUpTo = (int)buffer[1];
-
-
- count = sizeof(FileFormat);
- theErr = FSRead (refNum, &count, &FileFormat);
- if ( theErr != noErr ) {
- ParamText("\pError reading Preferences file", NIL, NIL, NIL);
- A_ErrorAlert();
- }
-
- PtoCstr((char *)FileFormat);
- if ( (i = strcmp((char *)FileFormat, "AIFF")) == 0 )
- SFoutputType = AIFF;
- else if ( (i = strcmp((char *)FileFormat, "FLOAT")) == 0 )
- SFoutputType = FLOAT;
- else if ( (i = strcmp((char *)FileFormat, "Sound Designer")) == 0 )
- SFoutputType = SD;
- else if ( (i = strcmp((char *)FileFormat, "INT16")) == 0 )
- SFoutputType = INT16;
- else { /* default */
- strcpy((char *)FileFormat, "FLOAT");
- SFoutputType = FLOAT;
- }
- CtoPstr((char *)FileFormat);
-
-
- count = sizeof(SFDirectoryName);
- theErr = FSRead (refNum, &count, &SFDirectoryName);
- if ( theErr != noErr ) {
- ParamText("\pError reading Preferences file", NIL, NIL, NIL);
- A_ErrorAlert();
- }
- theErr = FSClose(refNum);
-
- CreateSoundFile = FALSE;
- RunToPass1 = 0;
- RunToPass2 = 0;
- RunToPass3 = 0;
- switch( RunUpTo) {
- case Synthesize:
- CreateSoundFile = TRUE;
- break;
- case Pass3Test:
- RunToPass3 = 1;
- break;
- case Pass2Test:
- RunToPass2 = 1;
- break;
- case Pass1Test:
- RunToPass1 = 1;
- break;
- }
-
- out1_flag = 0;
- out2_flag = 0;
- out3_flag = 0;
-
- if( ReportFlags & 4 )
- out3_flag = 1;
- if ( ReportFlags & 2 )
- out2_flag = 1;
- if ( ReportFlags & 1 )
- out1_flag = 1;
- }
-
-
-
-
- void SaveMusic4C_Prefs()
- {
- int refNum;
- StringPtr volName;
- char buffer[2];
- long count;
- extern Str255 FileFormat;
- extern Str255 SFDirectoryName;
-
- theErr = FSOpen("\pMusic4C_Prefs", SysEnvData.sysVRefNum, &refNum);
- if (theErr) {
- theErr = Create("\pMusic4C_Prefs", SysEnvData.sysVRefNum, 'MU4C', 'TEXT');
- if ( theErr ) { /* call Error Alert */
- ParamText("\pCan't create Preferences file", NIL, NIL, NIL);
- A_ErrorAlert();
- }
- theErr = FSOpen("\pMusic4C_Prefs", SysEnvData.sysVRefNum, &refNum);
- }
- /* we have created & opened the file, write in the prefs */
- buffer[0] = ReportFlags;
- buffer[1] = RunUpTo;
- count = 2L;
- theErr = FSWrite( refNum, &count, &buffer);
-
- count = sizeof(FileFormat);
- theErr = FSWrite( refNum, &count, &FileFormat); /* default SF format */
-
- count = sizeof(SFDirectoryName);
- theErr = FSWrite( refNum, &count, &SFDirectoryName);
-
- if ( theErr != noErr ) {
- ParamText("\pError writing Preferences file", NIL, NIL, NIL);
- A_ErrorAlert();
- }
- volName = NIL;
- theErr = FlushVol (volName, SysEnvData.sysVRefNum);
- theErr = FSClose(refNum);
- }
-
-
-
-
- static pascal char MyFilter (theDialog, theEvent, itemHit)
- DialogPtr theDialog;
- EventRecord *theEvent;
- short *itemHit;
- {
- KeyMap theKeys;
- Rect tempRect;
- char xMyFilter;
- long keyCode, charCode;
-
- xMyFilter = FALSE;
- if (theEvent->what == mouseDown)
- {
- myPt = theEvent->where;
- GlobalToLocal(&myPt);
-
-
- SetRect(&tempRect, 160,70,377,90);
- if (PtInRect(myPt,&tempRect) == TRUE)
- {
- *itemHit = 999;
- xMyFilter = TRUE;
- }
-
- SetRect(&tempRect, 120,110,378,130);
- if (PtInRect(myPt,&tempRect) == TRUE)
- {
- *itemHit = 999;
- xMyFilter = TRUE;
- }
-
- }
- else if ( theEvent->what == keyDown ) {
- charCode = BitAnd(theEvent->message, charCodeMask);
- if ( charCode == 0x0D ) {
- SetRect(&tempRect, 240, 168, 320, 188);
- InvertRect(&tempRect);
- *itemHit = I_OK;
- xMyFilter = TRUE;
- }
- else {
- /* got some other keydown */
- *itemHit = 999;
- }
- }
- else
- *itemHit = 999;
-
- return(xMyFilter);
- }
-
-
- static void Refresh_Dialog(GetSelection)
- DialogPtr GetSelection;
- {
- Rect tempRect;
- short DType;
- Handle DItem;
- ControlHandle CItem;
- Rect theRect;
-
- GetDItem(GetSelection,I_OK, &DType, &DItem, &tempRect);
- PenSize(3, 3);
- InsetRect(&tempRect, -4, -4);
- FrameRoundRect(&tempRect, 16, 16);
- PenSize(1, 1);
-
- TextFont(systemFont);
- TextSize(12);
- MoveTo(165,84);
- DrawString("\pRun Up To: ");
- SetRect(&tempRect,238,71,370,88);
- EraseRect(&tempRect);
- MoveTo(251,84);
- switch (Popup_I_Run_Up_To)
- {
- case Pass1Test:
- DrawString("\pPass1 Test");
- /* disable pass2 & 3, Popup_I_Sound_File_Format */
- GetDItem(GetSelection, I_Pass2, &DType, &DItem, &theRect);
- CItem = (ControlHandle)DItem;
- HiliteControl(CItem, 255);
- DisableItem(GetSelection, I_Pass2);
- SetCtlValue(CItem, 0);
-
- GetDItem(GetSelection, I_Pass3, &DType, &DItem, &theRect);
- CItem = (ControlHandle)DItem;
- HiliteControl(CItem, 255);
- DisableItem(GetSelection, I_Pass3);
- SetCtlValue(CItem, 0);
-
- tempMenu = GetMenu(52);
- if ( tempMenu != NIL ) {
- InsertMenu(tempMenu,-1);
- DisableItem(tempMenu, 0);
- }
- break;
- case Pass2Test:
- DrawString("\pPass2 Test");
- GetDItem(GetSelection, I_Pass2, &DType, &DItem, &theRect);
- CItem = (ControlHandle)DItem;
- HiliteControl(CItem, 0);
- EnableItem(GetSelection, I_Pass2);
- if ( ReportFlags & 2)
- SetCtlValue(CItem, 1);
- else
- SetCtlValue(CItem, 0);
-
- GetDItem(GetSelection, I_Pass3, &DType, &DItem, &theRect);
- CItem = (ControlHandle)DItem;
- HiliteControl(CItem, 255);
- DisableItem(GetSelection, I_Pass3);
- SetCtlValue(CItem, 0);
-
- tempMenu = GetMenu(52);
- if ( tempMenu != NIL ) {
- InsertMenu(tempMenu,-1);
- DisableItem(tempMenu, 0);
- }
- break;
- case Pass3Test:
- DrawString("\pPass3 Test");
- GetDItem(GetSelection, I_Pass2, &DType, &DItem, &theRect);
- CItem = (ControlHandle)DItem;
- HiliteControl(CItem, 0);
- if ( ReportFlags & 2)
- SetCtlValue(CItem, 1);
- else
- SetCtlValue(CItem, 0);
-
- GetDItem(GetSelection, I_Pass3, &DType, &DItem, &theRect);
- CItem = (ControlHandle)DItem;
- HiliteControl(CItem, 0);
- if ( ReportFlags >= 4)
- SetCtlValue(CItem, 1);
- else
- SetCtlValue(CItem, 0);
-
- EnableItem(GetSelection, I_Pass2);
- EnableItem(GetSelection, I_Pass3);
- tempMenu = GetMenu(52);
- if ( tempMenu != NIL ) {
- InsertMenu(tempMenu,-1);
- DisableItem(tempMenu, 0);
- }
- break;
- case Synthesize:
- DrawString("\pCreate Sound File");
- GetDItem(GetSelection, I_Pass2, &DType, &DItem, &theRect);
- CItem = (ControlHandle)DItem;
- HiliteControl(CItem, 0);
- if ( ReportFlags & 2)
- SetCtlValue(CItem, 1);
- else
- SetCtlValue(CItem, 0);
-
- GetDItem(GetSelection, I_Pass3, &DType, &DItem, &theRect);
- CItem = (ControlHandle)DItem;
- HiliteControl(CItem, 0);
- if ( ReportFlags >= 4)
- SetCtlValue(CItem, 1);
- else
- SetCtlValue(CItem, 0);
-
- tempMenu = GetMenu(52);
- if ( tempMenu != NIL ) {
- InsertMenu(tempMenu,-1);
- EnableItem(tempMenu, 0);
- }
- EnableItem(GetSelection, I_Pass2);
- EnableItem(GetSelection, I_Pass3);
- break;
- default:
- DrawString("\p????");
- break;
- }
-
- FrameRect(&tempRect);
- MoveTo(tempRect.left + 1, tempRect.bottom);
- LineTo(tempRect.right, tempRect.bottom);
- LineTo(tempRect.right, tempRect.top + 1);
-
- TextFont(systemFont);
- TextSize(12);
- TextFont(systemFont);
- TextSize(12);
- MoveTo(125,124);
- DrawString("\pSound File Format: ");
- SetRect(&tempRect,253,111,371,128);
- EraseRect(&tempRect);
- MoveTo(266,124);
- if ( Popup_I_Run_Up_To == Synthesize ) {
- switch (Popup_I_Sound_File_Format)
- {
- case AIFF:
- DrawString("\pAIFF");
- break;
- case FLOAT:
- DrawString("\pFLOAT");
- break;
- case INT16:
- DrawString("\pINT16");
- break;
- case SD:
- DrawString("\pSound Designer");
- break;
- default:
- DrawString("\p????");
- break;
- }
- }
- FrameRect(&tempRect);
- MoveTo(tempRect.left + 1, tempRect.bottom);
- LineTo(tempRect.right, tempRect.bottom);
- LineTo(tempRect.right, tempRect.top + 1);
-
- TextFont(systemFont);
- TextSize(12);
- }
-
-
-
- void D_Preferences_Dialog()
- {
- DialogPtr GetSelection;
- Rect tempRect;
- short DType;
- Handle DItem;
- ControlHandle CItem;
- short itemHit;
- short temp;
- int i;
-
-
- GetSelection = GetNewDialog(3, NIL, (WindowPtr)-1);
-
- tempRect.top = GetSelection->portRect.top;
- tempRect.left = GetSelection->portRect.left;
- tempRect.bottom = GetSelection->portRect.bottom;
- tempRect.right = GetSelection->portRect.right;
- tempRect.top = ((screenBits.bounds.bottom - screenBits.bounds.top) - (tempRect.bottom - tempRect.top)) / 2;
- tempRect.left = ((screenBits.bounds.right - screenBits.bounds.left) - (tempRect.right - tempRect.left)) / 2;
- MoveWindow(GetSelection, tempRect.left, tempRect.top, TRUE);
-
- ShowWindow(GetSelection);
- SelectWindow(GetSelection);
- SetPort(GetSelection);
-
-
-
- /* Setup initial conditions */
- Popup_I_Run_Up_To = RunUpTo;
- Popup_I_Sound_File_Format = SFoutputType;
- Initial_Report_Flags = ReportFlags;
-
- /* report flags */
- GetDItem(GetSelection,I_Pass3, &DType, &DItem, &tempRect);
- CItem = (ControlHandle)DItem;
- if ( ReportFlags >= 4 && RunUpTo >= 3)
- SetCtlValue(CItem, 1);
- else
- SetCtlValue(CItem, 0);
-
-
- GetDItem(GetSelection,I_Pass2, &DType, &DItem, &tempRect);
- CItem = (ControlHandle)DItem;
- if ( ReportFlags & 2 && RunUpTo >= 2)
- SetCtlValue(CItem, 1);
- else
- SetCtlValue(CItem, 0);
-
- GetDItem(GetSelection,I_Pass1, &DType, &DItem, &tempRect);
- CItem = (ControlHandle)DItem;
- if ( ReportFlags & 1 && RunUpTo >= 1)
- SetCtlValue(CItem, 1);
- else
- SetCtlValue(CItem, 0);
-
-
-
- Refresh_Dialog(GetSelection);
-
- ExitDialog = FALSE;
-
- do {
- ModalDialog(&MyFilter, &itemHit);
- GetDItem(GetSelection, itemHit, &DType, &DItem, &tempRect);
- CItem = (ControlHandle)DItem;
-
- /* Handle it real time */
- if (itemHit == I_OK ) {
- RunUpTo = Popup_I_Run_Up_To;
- SFoutputType = Popup_I_Sound_File_Format;
- Initial_Report_Flags = ReportFlags;
- ExitDialog =TRUE;
- Refresh_Dialog(GetSelection);
- }
-
- if (itemHit == I_Cancel )
- {
- Popup_I_Run_Up_To = RunUpTo;
- Popup_I_Sound_File_Format = SFoutputType;
- ReportFlags = Initial_Report_Flags;
- ExitDialog =TRUE;
- }
-
- if (itemHit == I_Pass3 )
- {
- temp = GetCtlValue(CItem);
- SetCtlValue(CItem, ((temp + 1) & 1));
- temp = GetCtlValue(CItem);
- if ( temp ) {
- if ( ReportFlags < 4 )
- ReportFlags += 4;
- }
- else {
- if ( ReportFlags >= 4 )
- ReportFlags -= 4;
- }
- }
-
- if (itemHit == I_Pass2 )
- {
- temp = GetCtlValue(CItem);
- SetCtlValue(CItem, ((temp + 1) & 1));
- temp = GetCtlValue(CItem);
- if ( temp ) {
- if ( !(ReportFlags & 2) )
- ReportFlags += 2;
- }
- else {
- if ( ReportFlags & 2 )
- ReportFlags -= 2;
- }
- }
-
- if (itemHit == I_Pass1 )
- {
- temp = GetCtlValue(CItem);
- SetCtlValue(CItem, ((temp + 1) & 1));
- temp = GetCtlValue(CItem);
- if ( temp ) {
- if ( !(ReportFlags & 1) )
- ReportFlags += 1;
- }
- else {
- if ( ReportFlags & 1 )
- ReportFlags & 1;
- }
- }
-
-
- SetRect(&tempRect, 160,70,377,90);
- if ((PtInRect(myPt,&tempRect) == TRUE) && (itemHit == 999))
- {
- ChangedSelection = FALSE;
- TextFont(systemFont);
- TextSize(12);
-
- tempMenu= GetMenu(53);
- if (tempMenu != NIL)
- {
- InsertMenu (tempMenu,-1);
- SetRect(&tempRect,160,72,238,88);
- InvertRect(&tempRect);
- myPt.v = 72;
- myPt.h = 238;
- LocalToGlobal(&myPt);
-
- CheckItem(tempMenu,Popup_I_Run_Up_To,TRUE);
- for ( i = 1; i < 5; i ++ )
- if ( i != Popup_I_Run_Up_To )
- CheckItem(tempMenu,i,FALSE);
- else
- CheckItem(tempMenu,i,TRUE);
- Result = PopUpMenuSelect(tempMenu, myPt.v, myPt.h, Popup_I_Run_Up_To);
-
- if ((Popup_I_Run_Up_To != LoWord(Result)) && (LoWord(Result) > 0))
- {
- CheckItem(tempMenu,Popup_I_Run_Up_To,FALSE);
- ChangedSelection = TRUE;
- Popup_I_Run_Up_To = LoWord(Result);
- }
-
- DeleteMenu(53);
- InvertRect(&tempRect);
-
- if (ChangedSelection == TRUE)
- {
- SetRect(&tempRect,240,72,369,87);
- EraseRect(&tempRect);
-
- MoveTo(tempRect.left + 12,tempRect.top + 12);
- switch (Popup_I_Run_Up_To)
- {
- case Pass1Test:
- DrawString("\pPass1 Test");
- break;
- case Pass2Test:
- DrawString("\pPass2 Test");
- break;
- case Pass3Test:
- DrawString("\pPass3 Test");
- break;
- case Synthesize:
- DrawString("\pCreate Sound File");
- break;
- default:
- break;
- }
- }
- }
- TextFont(systemFont);
- TextSize(12);
- }
-
-
- SetRect(&tempRect, 120,110,378,130);
- if ((PtInRect(myPt,&tempRect) == TRUE) && (itemHit == 999))
- {
- ChangedSelection = FALSE;
- TextFont(systemFont);
- TextSize(12);
-
- tempMenu= GetMenu(52);
- if (tempMenu != NIL)
- {
- InsertMenu (tempMenu,-1);
- SetRect(&tempRect,120,112,253,128);
- InvertRect(&tempRect);
- myPt.v = 112;
- myPt.h = 253;
- LocalToGlobal(&myPt);
-
- for ( i = 1; i < 5; i ++ )
- if ( i != Popup_I_Sound_File_Format )
- CheckItem(tempMenu,i,FALSE);
- else
- CheckItem(tempMenu,i,TRUE);
- Result = PopUpMenuSelect(tempMenu, myPt.v, myPt.h, Popup_I_Sound_File_Format);
-
- if ((Popup_I_Sound_File_Format != LoWord(Result)) && (LoWord(Result) > 0))
- {
- CheckItem(tempMenu,Popup_I_Sound_File_Format,FALSE);
- ChangedSelection = TRUE;
- Popup_I_Sound_File_Format = LoWord(Result);
- }
-
- DeleteMenu(52);
- InvertRect(&tempRect);
-
- if (ChangedSelection == TRUE)
- {
- SetRect(&tempRect,255,112,370,127);
- EraseRect(&tempRect);
-
- MoveTo(tempRect.left + 12,tempRect.top + 12);
- switch (Popup_I_Sound_File_Format)
- {
- case AIFF:
- DrawString("\pAIFF");
- break;
- case FLOAT:
- DrawString("\pFLOAT");
- break;
- case INT16:
- DrawString("\pINT16");
- break;
- case SD:
- DrawString("\pSound Designer");
- break;
- default:
- break;
- }
- }
- }
- TextFont(systemFont);
- TextSize(12);
- }
- Refresh_Dialog(GetSelection);
- }
- while (ExitDialog == FALSE);
-
- if ( itemHit != I_Cancel ) {
- ReportFlags = 0;
- out1_flag = 0;
- out2_flag = 0;
- out3_flag = 0;
- /* Get results after dialog */
- GetDItem(GetSelection,I_Pass3, &DType, &DItem, &tempRect);
- CItem = (ControlHandle)DItem;
- temp = GetCtlValue(CItem);
- if ( (**CItem).contrlValue == 1) {
- ReportFlags = 4;
- out3_flag = 1;
- }
-
- GetDItem(GetSelection,I_Pass2, &DType, &DItem, &tempRect);
- CItem = (ControlHandle)DItem;
- temp = GetCtlValue(CItem);
- if ( (**CItem).contrlValue == 1) {
- ReportFlags += 2;
- out2_flag = 1;
- }
-
- GetDItem(GetSelection,I_Pass1, &DType, &DItem, &tempRect);
- CItem = (ControlHandle)DItem;
- temp = GetCtlValue(CItem);
- if ( (**CItem).contrlValue == 1) {
- ReportFlags += 1;
- out1_flag = 1;
- }
- }
-
-
- DisposDialog(GetSelection);
- switch (Popup_I_Sound_File_Format) {
- case SD:
- PstringCopy((char *)FileFormat, "\pSound Designer");
- break;
- case AIFF:
- PstringCopy((char *)FileFormat, "\pAIFF");
- break;
- case FLOAT:
- PstringCopy((char *)FileFormat, "\pFLOAT");
- break;
- case INT16:
- PstringCopy((char *)FileFormat, "\pINT16");
- break;
- }
-
- CreateSoundFile = FALSE;
- RunToPass1 = 0;
- RunToPass2 = 0;
- RunToPass3 = 0;
- switch( RunUpTo) {
- case Synthesize:
- CreateSoundFile = TRUE;
- break;
- case Pass3Test:
- RunToPass3 = 1;
- break;
- case Pass2Test:
- RunToPass2 = 1;
- break;
- case Pass1Test:
- RunToPass1 = 1;
- break;
- }
-
-
- SaveMusic4C_Prefs();
- }
-
-
-
-